package ArrayList_Advancepractice;

import java.util.Scanner;

public class HomeWork02 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
	    String str = sc.next();
	    int num = parseInt(str);
	    System.out.println("Converted integer: " + num);
	}
	
	public static int parseInt(String str) {
	    if (str == null || str.length() == 0) {
	        throw new IllegalArgumentException("Input string is empty");
	    }

	    int result = 0;
	    for (int i = 0; i < str.length(); i++) {
	        char c = str.charAt(i);
	        if (c < '0' || c > '9') {
	            throw new IllegalArgumentException("Input string contains non-numeric characters");
	        }
	        int digit = c - '0';
	        if (i == 0 && digit == 0 && str.length() > 1) {
	            throw new IllegalArgumentException("Input string starts with 0");
	        }
	        result = result * 10 + digit;
	    }
	    return result;
	}
}
